package com.atwei.mango.business.hello.service.impl;

import com.atwei.mango.business.hello.entity.Hello;
import com.atwei.mango.business.hello.mapper.HelloMapper;
import com.atwei.mango.business.hello.service.HelloService;;
//import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;


import java.util.List;

/**
 * @author liuwei
 * @date 2021/10/16 19:37
 */
@Log4j2
@Service
//@DS("master")
public class HelloServiceImpl extends ServiceImpl<HelloMapper,Hello> implements HelloService {


    @Override
    public void testMybatis() {
//        Hello hello = baseMapper.getByIdCustom(1);
//        log.info(hello.toString());
        Hello hello = new Hello();
        hello.setHello("123");

        baseMapper.insert(hello);
    }

    @Override
    public void testMybatisPlus() {
        Page<Hello> page = new Page<>(1,10);
        baseMapper.selectPageCustom(page);
//        log.info(page.getRecords().get(0));

    }

    @Override
    public void testSqlWrapperCustom() {
        QueryWrapper<Hello> queryWrapper = Wrappers.query();
        queryWrapper.eq("o.hello","hello");
        List<Hello> helloList = baseMapper.selectListWrapperCustom(queryWrapper);
        if(CollectionUtils.isEmpty(helloList)){
            log.info(helloList.get(0));
        }
        Page<Hello> page = new Page<>(1,10);
        baseMapper.selectPageWrapperCustom(page,queryWrapper);
        log.info(page.getRecords().get(0));
    }
}
